home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / A-B / add images.cpt / Source_1.c < prev    next >
Text File  |  1989-06-22  |  20KB  |  693 lines

  1. /* ===================================
  2.  
  3. File: Source_1.c
  4. Function: Handle all operations for this window
  5. History: 4/27/89 Original by Prototyper.
  6.  
  7. ================================= */
  8.  
  9. #include "Source_1.h"
  10. #include "pix_io.h"
  11. #include <ColorToolbox.h>
  12. #include <IM5protos.h>
  13.  
  14. extern RGBColor BlackRGB, whiteRGB, grayRGB;
  15. extern short pix_zoom;
  16. extern short src_changed; /* 1 if pict scrolled or changed, 0 otherwise */
  17.  
  18. CGrafPtr  proton_bmap; /* off-screen bitmap of proton image */
  19. PicHandle proton_pic;  /* handle to PICT for source 1 */
  20. Rect proton_rect;      /* size of offscreen pict */
  21. WindowPtr proton_Window;    /* Window pointer -- global variable */
  22.  
  23. short s1_off_top, s1_off_left;    /* offsets on the window from scrolling */
  24. static Str255 filename; /* local - image file, if any, associated with this window */
  25.  
  26. static void draw_proton( void );
  27.  
  28. static void HandleVScrollBar (short code, short Start, short Stop,
  29.                               short Increment, short LIncrement,
  30.                               ControlHandle theControl, Point myPt);
  31.  
  32. static void HandleHScrollBar (short code, short Start, short Stop,
  33.                               short Increment, short LIncrement,
  34.                               ControlHandle theControl, Point myPt);
  35.  
  36. static void Do_A_ScrollBar (short code, ControlHandle theControl, Point myPt);
  37.  
  38.  
  39.  
  40. /* *********************************** */
  41. /* These are the other includes for general routines */
  42.  
  43. #include <Strings.h>
  44. extern char *strcpy (Str255 *, char *);    /* LSC string prototype */
  45.  
  46. /* *********************************** */
  47.  
  48. #define      TRUE   1
  49. #define      FALSE  0
  50. #define      NIL    0
  51.  
  52. /* *********************************** */
  53.  
  54.  
  55.  
  56.  
  57. /* Scrollbar ID */
  58. #define    I_Vert_Scroll_bar     25
  59. /* Scrollbar ID */
  60. #define    I_Horiz_Scroll_bar     24
  61.  
  62. static ControlHandle CtrlHandle;    /* Control handle */
  63. static ControlHandle ScrollHHandle, ScrollVHandle;    /* Scrolling Control*/
  64. static Str255 sTemp;        /* Get text entered, temp holding */
  65. static OSErr MyErr;            /* General OS error return */
  66. static ControlHandle C_Vert_Scroll_bar;    /* Scroll bar  Control Handle */
  67. static ControlHandle C_Horiz_Scroll_bar;    /* Scroll bar  Control Handl*/
  68.  
  69. /* ====================================== */
  70.  
  71. /* Initialize us so all our routines can be activated */
  72. void Init_proton ()
  73. {
  74.     proton_Window = NIL;            /* Make sure other routines know we are not */
  75.     proton_rect.top = 0;
  76.     proton_rect.bottom = all_my_colors;
  77.     proton_rect.left = 0;
  78.     proton_rect.right = 300;
  79. }
  80.  
  81. /* ================================= */
  82.  
  83. void activate_proton (whichWindow, modifiers)
  84.     WindowPtr whichWindow;
  85.     long modifiers;
  86. {
  87.     WindowPtr SavePort;
  88.  
  89.     GetPort (&SavePort);
  90.     if ( modifiers & activeFlag != 0 )
  91.     {
  92.         SelectWindow(whichWindow);
  93.         SetPort(whichWindow);
  94.         ShowControl (ScrollHHandle);
  95.         ShowControl (ScrollVHandle);
  96.         DrawGrowIcon( whichWindow );
  97.         DrawControls( whichWindow );
  98.     }
  99.     else
  100.     {
  101.         SetPort(whichWindow);
  102.         HideControl (ScrollHHandle);
  103.         HideControl (ScrollVHandle);
  104.         DrawGrowIcon( whichWindow );
  105.         DrawControls( whichWindow );
  106.     }
  107.     SetPort(SavePort);
  108. }
  109.  
  110. typedef WStateData **WStateHandle;
  111.  
  112. void zoom_proton( where, whichWindow, code )
  113.     Point *where;
  114.     WindowPeek whichWindow;
  115.     short code;
  116. {
  117.     Point myPt;
  118.     WStateHandle WState;
  119.     
  120.     SetPort (whichWindow);
  121.  
  122.     if ( whichWindow->dataHandle != NIL )
  123.     {
  124.         WState = (WStateHandle) whichWindow->dataHandle;
  125.         (**WState).stdState = proton_rect;
  126.         (**WState).stdState.top += 40;
  127.         (**WState).stdState.left += 2;
  128.         (**WState).stdState.right += 2;
  129.         (**WState).stdState.bottom += 40;
  130.     }
  131.     myPt = *where;    /* Get mouse position */
  132.     GlobalToLocal (&myPt);    /* Make it relative */
  133.  
  134.     if (TrackBox (whichWindow, myPt, code) == TRUE)
  135.     {
  136.         EraseRect( &whichWindow->port.portRect );
  137.         ZoomWindow (whichWindow, code, TRUE);
  138.         InvalRect (&whichWindow->port.portRect);    
  139.     }
  140.     Resized_proton (proton_Window);
  141. }
  142.  
  143. void grow_proton( where, whichWindow )
  144.     Point *where;
  145.     WindowPtr whichWindow;
  146. {
  147.     Point myPt;
  148.     long mResult;
  149.  
  150.     SetPort (whichWindow);
  151.  
  152.     myPt = *where;    /* Get mouse position */
  153.     GlobalToLocal (&myPt);    /* Make it relative */
  154.  
  155.     mResult = GrowWindow (whichWindow, *where, &proton_rect);
  156.  
  157.     SizeWindow (whichWindow, LoWord (mResult),
  158.                 HiWord (mResult), TRUE);
  159.     Resized_proton (proton_Window);
  160. }
  161.  
  162. /* We were resized or zoomed, update the scrolling scrollbars */
  163. void Resized_proton (whichWindow)/* Resized this window */
  164.     WindowPtr whichWindow;        /* Window that was resized */
  165. {
  166.     WindowPtr SavePort;        /* Place to save the last port */
  167.  
  168.     GetPort (&SavePort);
  169.     SetPort (proton_Window);
  170.  
  171.     if (ScrollHHandle != NIL)
  172.     {
  173.         HLock ((Handle)ScrollHHandle);
  174.         HideControl (ScrollHHandle);
  175.  
  176.         InvalRect (&(*ScrollHHandle)->contrlRect);    /* Flag old position for update rout*/
  177.  
  178.         MoveControl (ScrollHHandle, proton_Window->portRect.left-1,
  179.             proton_Window->portRect.bottom - 15);
  180.         SizeControl (ScrollHHandle, (proton_Window->portRect.right 
  181.             - proton_Window->portRect.left) - 13, 16);
  182.  
  183.         ShowControl (ScrollHHandle);
  184.         HUnlock ((Handle)ScrollHHandle);
  185.     }
  186.     if (ScrollVHandle != NIL)
  187.     {
  188.         HLock ((Handle)ScrollVHandle);
  189.         HideControl (ScrollVHandle);
  190.  
  191.         InvalRect (&(*ScrollVHandle)->contrlRect);    /* Flag old position for update rout*/
  192.  
  193.         MoveControl (ScrollVHandle, proton_Window->portRect.right-15,
  194.             proton_Window->portRect.top-1);
  195.         SizeControl (ScrollVHandle, 16, (proton_Window->portRect.bottom 
  196.             - proton_Window->portRect.top) - 13);
  197.  
  198.         ShowControl (ScrollVHandle);
  199.         HUnlock ((Handle)ScrollVHandle);
  200.     }
  201.     InvalRect(&proton_Window->portRect);
  202.     DrawGrowIcon (proton_Window);    
  203.     SetPort (SavePort);
  204. }
  205. /* End of function */
  206.  
  207. /* ====================================== */
  208.  
  209. /* Update our window, someone uncovered a part of us */
  210. void UpDate_proton (whichWindow)
  211. WindowPtr whichWindow;
  212. {
  213.     WindowPtr SavePort;        /* Place to save the last port */
  214.  
  215.     GetPort (&SavePort);    /* Save the current port */
  216.     SetPort (proton_Window);    /* Set the port to my window */
  217.  
  218.     InvalRect(&proton_Window->portRect);
  219.  
  220.     BeginUpdate( proton_Window );
  221.     draw_proton();
  222.     DrawControls (proton_Window);    /* Draw all the controls */
  223.     DrawGrowIcon (proton_Window);    /* Draw the Grow box */
  224.     EndUpdate(proton_Window);
  225.     SetPort (SavePort);    /* Restore the old port */
  226. }
  227.  
  228. static void draw_proton()
  229. {
  230.     Rect clipper;
  231.     Rect offrect; /* coords in offscreen bitmap */
  232.     short i;
  233.  
  234.     clipper.top = proton_Window->portRect.top;
  235.     clipper.bottom = proton_Window->portRect.bottom - 15;
  236.     clipper.right = proton_Window->portRect.right - 15;
  237.     clipper.left = proton_Window->portRect.left;
  238.     
  239.     ClipRect( &clipper );
  240.     
  241.     EraseRect( &clipper );
  242.     if ( s1_off_top < proton_rect.bottom  && 
  243.             s1_off_left < proton_rect.right )
  244.     {
  245.         if ( proton_bmap != NIL )
  246.         {
  247.             offrect = clipper;
  248.             offrect.top += s1_off_top;
  249.             offrect.bottom += s1_off_top;
  250.             if ( offrect.bottom > proton_rect.bottom + s1_off_top )
  251.             {
  252.                 offrect.bottom = proton_rect.bottom;
  253.                 clipper.bottom = proton_rect.bottom - s1_off_top;
  254.             }
  255.             offrect.left += s1_off_left;
  256.             offrect.right += s1_off_left;
  257.             if ( offrect.right > proton_rect.right + s1_off_left )
  258.             {
  259.                 offrect.right = proton_rect.right;
  260.                 clipper.right = proton_rect.right - s1_off_left;
  261.             }
  262.  
  263.             HLock((Handle) (proton_bmap->portPixMap));
  264.             CopyBits( *(proton_bmap->portPixMap), &thePort->portBits, 
  265.                     &offrect, &clipper, (short) srcCopy, 
  266.                     (RgnHandle) NIL);
  267.             HUnlock((Handle) (proton_bmap->portPixMap));
  268.         }
  269.         else
  270.         {
  271.             SetOrigin( s1_off_left, s1_off_top );
  272.             for ( i = 0; i < all_my_colors; i++)
  273.             {
  274.                 PmForeColor( i );
  275.                 MoveTo( 0, i );
  276.                 LineTo( 300, i );
  277.             }
  278.             SetOrigin( 0, 0);
  279.         }
  280.     }
  281.     ClipRect( &proton_Window->portRect ); 
  282. }
  283.  
  284. /* End of UpDate */
  285.  
  286. /*  ===========================================  */
  287. /* vertical scroll bar */
  288.  
  289. static void HandleVScrollBar (code, Start, Stop, Increment, LIncrement,
  290.                               theControl, myPt)
  291.     short code;                    /*  Selection code for part of scroll bar  */
  292.     short Start;                /*  Minimum value the scroll bar can assume */
  293.     short Stop;                    /*  Maximum value the scroll bar can assume */
  294.     short LIncrement, Increment;    /*  Increment to move when pressed in an*/
  295.     ControlHandle theControl;    /*  Handle to the scroll bar control */
  296.     Point myPt;                    /*  Returned point from track the scrollbar */
  297. {                        /*  Start of this function */
  298.     short theValue;            /*  Value of the scrollbar */
  299.     long MaxTick;            /*  Timer used for repeat scrolling */
  300.  
  301.     do                        /* Do the scroll as long as the button is do*/
  302.     {                    /* Timer used for repeat scrolling */
  303.         HiliteControl (theControl, code);    /* Darken the arrow */
  304.         theValue = GetCtlValue (theControl);    /* Get current state */
  305.  
  306.         if (code == inUpButton)    /* See if in the Up arrow */
  307.         {
  308.             theValue = theValue - Increment;    /* Subtract the single d*/
  309.             if (theValue < Start)    /* Check for boundary conditions */
  310.                 theValue = Start;    /* Pin at the start value */
  311.         }
  312.  
  313.         if (code == inDownButton)    /* See if in the Down arrow */
  314.         {
  315.             theValue = theValue + Increment;    /* Add the single decrem*/
  316.             if (theValue > Stop)    /* Check for boundary conditions */
  317.                 theValue = Stop;    /* Pin at the stop value */
  318.         }
  319.  
  320.         if (code == inPageUp)    /* See if in the up/left grey area */
  321.         {
  322.             theValue = theValue - LIncrement;    /* Subtract the page inc*/
  323.             if (theValue < Start)    /* Check for boundary conditions */
  324.                 theValue = Start;    /* Pin at the Start value */
  325.         }
  326.  
  327.         if (code == inPageDown)    /* See if in the down/right grey area */
  328.         {
  329.             theValue = theValue + LIncrement;    /* Add the page incremen*/
  330.             if (theValue > Stop)    /* Check for boundary conditions */
  331.                 theValue = Stop;    /* Pin at the Stop value */
  332.         }
  333.  
  334.         if (code == inThumb)    /* See if in the drag box area */
  335.         {
  336.             code = TrackControl (theControl, myPt, NIL);    /* Let the O*/
  337.             theValue = GetCtlValue (theControl);    /* Get current state*/
  338.         }
  339.  
  340.         SetCtlValue (theControl, theValue);    /* Set new state */
  341.  
  342.         s1_off_top = (short) ( (double) (proton_rect.bottom - proton_rect.top) 
  343.                             * (double) theValue / (double) (Stop - Start) );
  344.         
  345.         draw_proton();
  346.  
  347.         MaxTick = TickCount () + 9;    /* Time delay for auto-scroll */
  348.         do    /* Start of delay routine */
  349.         { /* Spin on doing nothing */
  350.         } while ((Button () == TRUE) && (TickCount () <= MaxTick));    /* E*/
  351.  
  352.         HiliteControl (theControl, 0);    /* Lighten the arrow */
  353.     }                    /* End for StillDown */
  354.     while (StillDown () == TRUE);    /* End for StillDown */
  355. }
  356.  
  357. /* End for HandleVScrollBar */
  358.  
  359. /* ====================================================== */
  360.  
  361. /* horizontal scroll bar */
  362.  
  363. static void HandleHScrollBar (code, Start, Stop, Increment, LIncrement,
  364.                               theControl, myPt)
  365.     short code;                    /*  Selection code for part of scroll bar  */
  366.     short Start;                /*  Minimum value the scroll bar can assume */
  367.     short Stop;                    /*  Maximum value the scroll bar can assume */
  368.     short LIncrement, Increment;    /*  Increment to move when pressed in an*/
  369.     ControlHandle theControl;    /*  Handle to the scroll bar control */
  370.     Point myPt;                    /*  Returned point from track the scrollbar */
  371. {                        /*  Start of this function */
  372.     short theValue;            /*  Value of the scrollbar */
  373.     long MaxTick;            /*  Timer used for repeat scrolling */
  374.  
  375.     do                        /* Do the scroll as long as the button is do*/
  376.     {                    /* Timer used for repeat scrolling */
  377.         HiliteControl (theControl, code);    /* Darken the arrow */
  378.         theValue = GetCtlValue (theControl);    /* Get current state */
  379.  
  380.         if (code == inUpButton)    /* See if in the Up arrow */
  381.         {
  382.             theValue = theValue - Increment;    /* Subtract the single d*/
  383.             if (theValue < Start)    /* Check for boundary conditions */
  384.                 theValue = Start;    /* Pin at the start value */
  385.         }
  386.  
  387.         if (code == inDownButton)    /* See if in the Down arrow */
  388.         {
  389.             theValue = theValue + Increment;    /* Add the single decrem*/
  390.             if (theValue > Stop)    /* Check for boundary conditions */
  391.                 theValue = Stop;    /* Pin at the stop value */
  392.         }
  393.  
  394.         if (code == inPageUp)    /* See if in the up/left grey area */
  395.         {
  396.             theValue = theValue - LIncrement;    /* Subtract the page inc*/
  397.             if (theValue < Start)    /* Check for boundary conditions */
  398.                 theValue = Start;    /* Pin at the Start value */
  399.         }
  400.  
  401.         if (code == inPageDown)    /* See if in the down/right grey area */
  402.         {
  403.             theValue = theValue + LIncrement;    /* Add the page incremen*/
  404.             if (theValue > Stop)    /* Check for boundary conditions */
  405.                 theValue = Stop;    /* Pin at the Stop value */
  406.         }
  407.  
  408.         if (code == inThumb)    /* See if in the drag box area */
  409.         {
  410.             code = TrackControl (theControl, myPt, NIL);    /* Let the O*/
  411.             theValue = GetCtlValue (theControl);    /* Get current state*/
  412.         }
  413.  
  414.         SetCtlValue (theControl, theValue);    /* Set new state */
  415.  
  416.         s1_off_left = (short) ( (double)(proton_rect.right - proton_rect.left) 
  417.                              * (double) theValue / (double) (Stop - Start) );
  418.  
  419.         draw_proton();
  420.         
  421.         MaxTick = TickCount () + 9;    /* Time delay for auto-scroll */
  422.         do    /* Start of delay routine */
  423.         { /* Spin on doing nothing */
  424.         } while ((Button () == TRUE) && (TickCount () <= MaxTick));    /* E*/
  425.  
  426.         HiliteControl (theControl, 0);    /* Lighten the arrow */
  427.     }                    /* End for StillDown */
  428.     while (StillDown () == TRUE);    /* End for StillDown */
  429. }
  430.  
  431. /* End for HandleHScrollBar */
  432.  
  433. static void Do_A_ScrollBar (code, theControl, myPt)    /* Handle a ScrollBa*/
  434.     short code;                    /* Which place in scrollbar was pressed */
  435.     ControlHandle theControl;    /* Which place in scrollbar was pressed */
  436.     Point myPt;                    /* Where the scrollbar was pressed */
  437. {                        /* Start of a ScrollBar being pressed */
  438.     short RefCon;
  439.  
  440.     RefCon = GetCRefCon (theControl);    /* get control refcon */
  441.  
  442.     switch (RefCon)
  443.     {
  444.         case I_Vert_Scroll_bar:
  445.             HandleVScrollBar (code, 1, 100, 1, 10, theControl, myPt);
  446.             src_changed = TRUE;
  447.             break;
  448.  
  449.         case I_Horiz_Scroll_bar:
  450.             HandleHScrollBar (code, 1, 100, 1, 10, theControl, myPt);
  451.             src_changed = TRUE;
  452.             break;
  453.  
  454.         default:
  455.             break;
  456.     }
  457. }
  458.  
  459. /* Handle a ScrollBar being pressed */
  460.  
  461. /* ================================= */
  462.  
  463. /* Open our window and draw everything */
  464. void Open_proton ()
  465. {
  466.     Rect tempRect;
  467.  
  468.     if (proton_Window == NIL)    /* Handle an open when already opened */
  469.     {
  470.         /* proton_Window = (WindowPtr) GetNewCWindow (8, NIL, (WindowPtr) - 1); --  Get the w*/
  471.  
  472.         tempRect.top = 139;
  473.         tempRect.bottom = 334;
  474.         tempRect.left = 3;
  475.         tempRect.right = 194;
  476.         proton_Window = (WindowPtr) NewCWindow( (Ptr) NIL, &tempRect, "\pProton", 
  477.             (Boolean) true, 8, (WindowPtr)-1, (Boolean)false, 8L);
  478.  
  479.         /* MoveWindow (proton_Window, tempRect.left, tempRect.top, TRUE); */
  480.  
  481.         SetPort (proton_Window);
  482.  
  483.         /*  Make a scroll bar, Vert Scroll bar   */
  484.         ScrollVHandle = GetNewControl (I_Vert_Scroll_bar, proton_Window);
  485.  
  486.         /*  Make a scroll bar, Horiz Scroll bar   */
  487.  
  488.         ScrollHHandle = GetNewControl (I_Horiz_Scroll_bar, proton_Window);
  489.  
  490.         ShowWindow (proton_Window);
  491.         SelectWindow (proton_Window);
  492.  
  493.         /* NSetPalette( proton_Window, mypalette, pmFgUpdates); */
  494.         /* RGBBackColor(&whiteRGB); */
  495.         /* RGBForeColor(&BlackRGB); /* copybits usually expect black fore and white back */
  496.         /* OpColor(&grayRGB); */
  497.  
  498.         Resized_proton (proton_Window);
  499.     }                    /* End for if (proton_Window<>nil) */
  500.     else
  501.     {
  502.         SelectWindow (proton_Window);    /* Already open, so show it */
  503.     }
  504. }
  505.  
  506. /* End of open function */
  507.  
  508. /* ================================= */
  509.  
  510. /* Handle action to our window, like controls */
  511. void Do_proton (myEvent)
  512.     EventRecord *myEvent;
  513. {
  514.     short RefCon;            /* RefCon for controls */
  515.     short code;                /* Location of event in window or controls */
  516.     short theValue;            /* Current value of a control */
  517.     WindowPtr whichWindow;    /* Window pointer where event happened */
  518.     Point myPt;                /* Point where event happened */
  519.     ControlHandle theControl;    /* Handle for a control */
  520.     WindowPtr SavePort;
  521.     
  522.     /* Start of Window handler */
  523.     if (proton_Window != NIL)    /* Handle only when the window is valid */
  524.     {
  525.         GetPort (&SavePort);
  526.         SetPort(proton_Window);
  527.         
  528.         SetOrigin(0, 0);
  529.         
  530.         code = FindWindow (myEvent->where, &whichWindow);    /* Get where*/
  531.  
  532.         if ((myEvent->what == mouseDown) && (proton_Window == whichWindow))
  533.         {
  534.             myPt = myEvent->where;    /* Get mouse position */        
  535.             GlobalToLocal (&myPt);    /* Make it relative */
  536.         }
  537.  
  538.         if ((proton_Window == whichWindow) && (code == inContent))    /* for o*/
  539.         {
  540.  
  541.             code = FindControl (myPt, whichWindow, &theControl);    /* G*/
  542.  
  543.             if ((code == inUpButton) || (code == inDownButton)
  544.                 || (code == inThumb) || (code == inPageDown)
  545.                 || (code == inPageUp))
  546.                 Do_A_ScrollBar (code, theControl, myPt);    /* Do scroll*/
  547.             if (code != 0)    /* Check type of control */
  548.                 code = TrackControl (theControl, myPt, NIL);    /* Track*/
  549.  
  550.         }                /* End for if (proton_Window==whichWindow) */
  551.     }                    /* End for if (proton_Window != NIL) */
  552.     SetPort(SavePort);
  553. }
  554.  
  555. /* End of function */
  556.  
  557. /* ================================= */
  558.  
  559. void read_proton()
  560. /* reads a PICT file and displays it in proton window */
  561. {
  562.     short width, height;
  563. /*
  564.     put up open-file dialog
  565.     if not cancelled then
  566.         clear out current proton picture
  567.         open selected file
  568.         skip header 512 bytes
  569.         read to find out how big the picture is going to be, and then rewind a bit
  570.         allocate appropriate handle
  571.         read file into the handle
  572.         use the pict Frame in determining how big to create the pixmap for source1
  573.         create pixmap
  574.         copy the PICT into the pixmap
  575.     end if
  576. */
  577.     GDHandle theMaxDevice;
  578.     Point place;
  579.     Point tempP;
  580.     Rect globRect;
  581.     SFReply theReply;
  582.     SFTypeList theList;
  583.     short ix, iy;
  584.  
  585.     place.h = 60;
  586.     place.v = 60;
  587.     theList[0] = 'PICT';
  588.  
  589.     SFGetFile ( place, "\pOpen a GrayScale PICT file", NIL, 1, theList, NIL, &theReply );
  590.  
  591.     SetPort( proton_Window );
  592.  
  593.     if ( theReply.good != 0 )
  594.     {
  595.         if ( proton_pic != NIL )
  596.         {
  597.             DisposHandle( (Handle) proton_pic );
  598.         }
  599.         if ( GetPic( theReply, &proton_pic ) )
  600.         {
  601.             proton_rect = (**proton_pic).picFrame;
  602.             /* copy that PICT to our pixmap, converting it to use the Flourine colors */
  603.             
  604.             height = proton_rect.bottom - proton_rect.top;
  605.             width = proton_rect.right - proton_rect.left;
  606.             proton_rect.top = 0;
  607.             proton_rect.bottom = height;
  608.             proton_rect.left = 0;
  609.             proton_rect.right = width;
  610.  
  611.             tempP.v = proton_Window->portRect.top;
  612.             tempP.h = proton_Window->portRect.left;
  613.             LocalToGlobal(&tempP);
  614.             globRect.top = tempP.v;
  615.             globRect.left = tempP.h;
  616.  
  617.             tempP.v = proton_Window->portRect.bottom;
  618.             tempP.h = proton_Window->portRect.right;
  619.             LocalToGlobal(&tempP); 
  620.             globRect.bottom = tempP.v;
  621.             globRect.right = tempP.h;
  622.  
  623.             theMaxDevice = GetMaxDevice(&globRect); /*get the maxDevice*/
  624.  
  625.             proton_bmap = pic_to_bmap( proton_pic, &proton_rect, theMaxDevice );
  626.  
  627.             if ( proton_bmap != NIL )
  628.             {
  629.                 DisposHandle( (Handle) proton_pic );
  630.             }
  631.             src_changed = TRUE;
  632.         }
  633.         else /* failed to get a pict */
  634.         {
  635.             clear_proton();
  636.         }
  637.     }
  638.     UpDate_proton (proton_Window);
  639. }
  640.  
  641. void paste_proton() /* !!! change this to use off screen bitmap */
  642. /* paste a PICT from the clipboard and displays it in proton window */
  643. {
  644.     long length, offset;
  645.     long width, height, size;
  646. /*
  647.     look for PICT resource in clipboard
  648.     if there is a PICT then
  649.         clear out current proton picture
  650.         read to find out how big the picture is going to be, and then rewind a bit
  651.         allocate appropriate handle
  652.         read paste into the handle
  653.         use the pict Frame in determining how big to create the pixmap for source1
  654.         create pixmap
  655.         copy the PICT into the pixmap
  656.     end if
  657. */
  658.     proton_pic = (PicHandle) NewHandle(0);
  659.     length = GetScrap( (Handle) proton_pic, 'PICT', &offset);
  660.     if ( length > 0 )
  661.     {
  662.         proton_rect = (**proton_pic).picFrame;
  663.         width = proton_rect.right - proton_rect.left;
  664.         height = proton_rect.bottom - proton_rect.top;
  665.         size = width * height;
  666.         /* allocate offscreen-buffer based on size, etc.*/
  667.         proton_rect.top = 0;
  668.         proton_rect.left = 0;
  669.         proton_rect.bottom = height;
  670.         proton_rect.right = width;
  671.     }
  672.     UpDate_proton (proton_Window);
  673. }
  674.  
  675. void clear_proton() /* !!! change this to use off screen bit map */
  676. /* "cut" without clipboard */
  677. {
  678.     if (proton_pic != NIL )
  679.     {
  680.         DisposHandle( (Handle) proton_pic );
  681.     }
  682.     proton_rect.top = 0;
  683.     proton_rect.bottom = all_my_colors;
  684.     proton_rect.left = 0;
  685.     proton_rect.right = 300;
  686.     UpDate_proton (proton_Window);
  687. }
  688.  
  689. void crop_proton()
  690. {
  691.  
  692. }
  693.